App.Presenter.GroupingPagePresenter = (function (App) {

    var _router = App.Router;
    var _page = App.View.GroupingPage;
    var _view = App.View;
    var _cache = App.Data.Cache;
    var _cont = App.Data.Constants;
    var _Custom = App.Model.Custom;
    var _customBiz = App.Biz.CustomBiz;
    var _element = App.Data.Element;
    var _presenter = App.Presenter;

    // 分组类型
    var _type = 0;
    var _customs = [];

    var onLoad = function (page_id) {
        _page.loadPage(page_id);
    };

    var setData = function (data) {
        if (data) {
            _type = data.type;
            _customs = _customBiz.getCustomGroupByType(_type);
            if (data.keyword) {
                _view.Helper.setTitle('搜索客户');
                _page.setSearchKeyword(data.keyword);
            } else {
                _view.Helper.setTitle(_Custom.GROUP_TITLE[_type]);
            }
            _page.buildCustomList(_customs);
            _page.bindListItems(_onClickCustomItem);
        }
    };

    var _onClickCustomItem = function (index) {
        _customs[index] && enterCustom(_customs[index]);
    };

    var enterCustom = function (custom) {
        _router.gotoArticle(_element.SECTIONS.CUSTOM, PAGE_CUSTOM);
        _presenter.CustomPagePresenter.setData({
            action:_presenter.CustomPagePresenter.ACTION_TYPE.DETAILS,
            custom:custom
        });
    };

    return {
        onLoad:onLoad,
        setData:setData
    };

})(App);

// 注册展示器
App.Presenter.register(PAGE_GROUPING, App.Presenter.GroupingPagePresenter);